package cn.wolfcode.shop.cloud.service.impl;

import cn.wolfcode.shop.cloud.domain.SeckillOrder;
import cn.wolfcode.shop.cloud.mapper.SeckillOrderMapper;
import cn.wolfcode.shop.cloud.redis.RedisService;
import cn.wolfcode.shop.cloud.redis.SecKillKeyPrefix;
import cn.wolfcode.shop.cloud.service.ISeckillOrderService;
import cn.wolfcode.shop.cloud.util.SeckillCodeMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class SeckillOrderServiceImpl implements ISeckillOrderService {
    @Autowired
    private SeckillOrderMapper seckillOrderMapper;

    @Autowired
    private RedisService redisService;
    @Override
    public SeckillOrder selectByUserIdAndSeckillId(Long id, Long seckillId) {
        return seckillOrderMapper.queryByUserIdAndSeckillId(id,seckillId);
    }


    public void creatSeckillOrder(Long userId, Long seckillId, String orderNo) {
        SeckillOrder seckillOrder = new SeckillOrder();
        seckillOrder.setOrderNo(orderNo);
        seckillOrder.setSeckillId(seckillId);
        seckillOrder.setUserId(userId);
        seckillOrderMapper.save(seckillOrder);
        //放入redis中
        //前缀：userid: seckillId
        redisService.set(SecKillKeyPrefix.SECKILL_CREATE_ORDER,userId+":"+seckillId,true);
    }
}
